﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Jewelnoid
{
    class MenuBackground
    {
        public Background backgroundImage;
        public Background textArea1Image;
        public Background textArea2Image;
        public List<List<Block>> blocksList;
        
        private int maxLine;
        private int maxColumn;

        public MenuBackground()
        {
            Texture2D blockTexture = Game1.self.Content.Load<Texture2D>("Block");

            this.backgroundImage = new Background(Game1.self.Content.Load<Texture2D>("Background"));
            this.textArea1Image = new Background(Game1.self.Content.Load<Texture2D>("Background"));
            this.textArea2Image = new Background(Game1.self.Content.Load<Texture2D>("Background"));
            this.blocksList = new List<List<Block>>();

            maxLine = Game1.self.graphics.PreferredBackBufferHeight / (blockTexture.Height + 5);
            maxColumn = Game1.self.graphics.PreferredBackBufferWidth / (blockTexture.Width + 5);
            textArea1Image.scale = new Vector2(0.5f, 0.28f);
            textArea1Image.position.Y = Game1.self.graphics.PreferredBackBufferHeight / 4 - 3;
            textArea2Image.scale = new Vector2(0.5f, 0.28f);
            textArea2Image.position.Y = 3 * Game1.self.graphics.PreferredBackBufferHeight / 4 + 3;


            Vector2 startposition = new Vector2(blockTexture.Width / 2 + 2, blockTexture.Height / 2 + 7);
            Color randomColor = Level.genericColor(7); //Porque eu gosto do número 7. O valor da seed não importa aqui, pois só ocorrerá 1 vez ao iniciar o Menu principal.

            for (int i = 0; i < maxLine; i++)
            {
                List<Block> blockLine = new List<Block>();
                
                randomColor = Block.nextColor(randomColor);

                for (int j = 0; j < maxColumn; j++)
                {
                    blockLine.Add(new Block(blockTexture, new Vector2(j * (blockTexture.Width + 5) + startposition.X, i * (blockTexture.Height + 5) + startposition.Y), randomColor));
                }

                this.blocksList.Add(blockLine);
            }
        }

        public void draw(SpriteBatch spriteBatch)
        {
            backgroundImage.draw(spriteBatch);

            for (int i = 0; i < maxLine; i++)
            {
                for (int j = 0; j < maxColumn; j++)
                {
                    blocksList[i][j].draw(spriteBatch);
                }
            }

            textArea1Image.draw(spriteBatch);
            textArea2Image.draw(spriteBatch);
        }

        public void update()
        {
        }
    }
}
